import { axios } from "@/utils/request.js";

// 获取文章
export function getArticleById(id) {
  var url = `/cms/api/content/${id}.do`;
  return axios.get(url);
}

// 获取文章列表
export function getArticleList(params) {
  var url = `/cms/api/content/list.do`;
  return axios.get(url, {
    params: params,
  });
}

// 获取栏目列表
export function getCategoryList(params) {
  var url = `/cms/api/category/list.do`;
  return axios.get(url, {
    params: params,
  });
}

//格式化图片路径
export function imgUrl(str) {
  if (!str) {
    return null;
  }
  var array = JSON.parse(str);
  if (!array[0]) {
    return require("@/assets/img/blank-profile-picture-973460_640.png");
  }
  return array[0].path;
}

//将json转换为js对象
export function jsonStringTojsObject(str) {
  if (!str) {
    return null;
  }
  return JSON.parse(str);
}
